from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import date
from src.schemas.response import SuccessResponse, PaginatedResponse


class CheckinStatusResponse(BaseModel):
    """打卡状态响应"""
    is_checkin: bool = Field(..., description="今日是否已打卡")
    total_checkin_days: int = Field(..., description="总打卡天数")
    continuous_checkin_days: int = Field(..., description="当前连续打卡天数")
    last_checkin_date: Optional[str] = Field(None, description="最后打卡日期")
    current_points: int = Field(..., description="当前积分")


class CheckinResponse(BaseModel):
    """打卡操作响应"""
    is_checkin: bool = Field(..., description="今日是否已打卡")
    total_checkin_days: int = Field(..., description="总打卡天数")
    continuous_checkin_days: int = Field(..., description="当前连续打卡天数")
    points_awarded: int = Field(..., description="本次获得的积分")
    current_points: int = Field(..., description="当前总积分")
    checkin_date: str = Field(..., description="打卡日期")


class CheckinHistoryItem(BaseModel):
    """打卡历史记录项"""
    id: int = Field(..., description="记录ID")
    checkin_date: str = Field(..., description="打卡日期")
    points_awarded: int = Field(..., description="获得的积分")
    continuous_days: int = Field(..., description="打卡时的连续天数")
    created_at: str = Field(..., description="创建时间")


class CheckinHistoryData(BaseModel):
    """打卡历史数据"""
    records: List[CheckinHistoryItem] = Field(..., description="打卡记录列表")
    total: int = Field(..., description="总记录数")
    page: int = Field(..., description="当前页码")
    limit: int = Field(..., description="每页数量")
    has_more: bool = Field(..., description="是否有更多数据")


class CheckinSummaryRequest(BaseModel):
    """打卡汇总查询请求"""
    year: int = Field(..., description="年份", ge=2020, le=2030)
    month: int = Field(..., description="月份", ge=1, le=12)


class CheckinSummaryItem(BaseModel):
    """打卡汇总项"""
    checkin_date: str = Field(..., description="打卡日期")


class CheckinSummaryData(BaseModel):
    """打卡汇总数据"""
    year: int = Field(..., description="查询年份")
    month: int = Field(..., description="查询月份")
    total_checkin_count: int = Field(..., description="该月总打卡次数")
    max_continuous_days: int = Field(..., description="该月最大连续打卡天数")
    checkin_records: List[str] = Field(..., description="打卡日期列表")


# API响应类型定义
CheckinStatusApiResponse = SuccessResponse[CheckinStatusResponse]
CheckinApiResponse = SuccessResponse[CheckinResponse]
CheckinHistoryApiResponse = SuccessResponse[CheckinHistoryData]
CheckinSummaryApiResponse = SuccessResponse[CheckinSummaryData]